var $ = require('../../lib/jquery');
var util = require('./common/util');
var minHeight = require('./common/minHeight');
var falg=true,countdown =180;
minHeight.init();
$('.js_code').on('click',function(){
    var login=$('.js_phone').val();
    var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
    if(!myreg.test(login)){
        alert('手机号有误') 
      
    }else{
        if(falg){
            falg=false;
            util.fetch('login/user/SendMessage?type=0&fun=0&phoneNum='+login).then(function (res){
                if(res.code=='USR000'){
                    settime();
                    sessionStorage.setItem('login',login);
                }
            }).fail(function(res){
                alert(res.msg)
            })
        }
        
    }
   
})
function settime() {
    if (countdown == 0) {
        falg=true;
        $('.js_code').html('获取验证码');
        $('.js_code').removeClass('js_code1');
        countdown = 180;
    } else {
        countdown--;
        $('.js_code').html(countdown+'s');
        $('.js_code').addClass('js_code1');
     
        setTimeout(function() {
            settime()
        },1000)
    }

}

$('.js_first').on('click',function (){
    var login=$('.js_phone').val();
    var code=$('.code').val();
    var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
    if(login==''){
        alert('请填写手机号')
    }else if(!myreg.test(login)){
        alert('手机号有误') 
    }else if(code==''){
        alert('请填写验证码')
    }else{
        util.fetch('login/user/validatCode?fun=0&login=' + login + '&code=' + code).then(function (res) {
             sessionStorage.setItem('login', login);
             sessionStorage.setItem('code', code);
            $('.first').addClass('hide');
            $('.five').removeClass('hide');
             

        }).fail(function (res) {
            alert(res.msg);
            countdown =0;
        })
    }
       
        
    })


$('.js_five').on('click',function (){
   var passWord=$('.js_word').val();
   var reg = /((?=.*\d)(?=.*\D)|(?=.*[a-zA-Z])(?=.*[^a-zA-Z]))(?!^.*[\u4E00-\u9FA5].*$)^\S{4,16}$/;
   if(passWord==''){
       alert('请填写密码')
   }else if(!reg.test(passWord)){
        alert('字母，数字，符号，至少两种')
    }else if(passWord!= $('.js_word1').val()){
       alert('两次密码不一样')
   }else{
       util.fetch('login/user/resetPassword',{
           login: sessionStorage.getItem('login'),
           newPassWord: passWord,
           checkcode: sessionStorage.getItem('code'),
         }).then(function (res){
             alert('密码设置成功');
            window.location.href = './login.html';
            sessionStorage.removeItem('code');

         }).fail(function (res){
           alert(res.msg);
       })
   }
  
})
$('.js_a2').on('click', function () {
    location.href = 'http://223.71.187.80:9010/bmxt';
})